package performance;

//start extract CallBenchmark
public class CallBenchmark {

    public static double aDouble;
    public static double aDouble1;
    public static double aDouble2;
    public static double aDouble3;

    public static double compute( double x ) {
	aDouble1 = aDouble1 + aDouble;
	aDouble2 = aDouble2 + 2 * aDouble;
	aDouble3 = aDouble3 + 3 * aDouble;
	return x / 1.000001;
    }

    public static void main(String args[]) {
	int numberOfIterations = 100000000;
	DoNothing target = new DoNothing();
	long time0 = System.currentTimeMillis();
	aDouble = 123456789.0;
	aDouble1 = 0;
	aDouble2 = 2;
	aDouble3 = 3;
	for ( int j = 0; j < numberOfIterations; j++ ) 
	    aDouble = compute(aDouble); 
	long time1 = System.currentTimeMillis();
	aDouble = 123456789.0;
	aDouble1 = 0;
	aDouble2 = 2;
	aDouble3 = 3;
	for ( int j = 0; j < numberOfIterations; j++ )
	    target.doNothing( ); 
	long time2 = System.currentTimeMillis();
	
	double timeForCall = (time2 - time1) - (time1 - time0);
	System.out.println( "CallBenchmark: " + (time1 - time0) 
			    + " milliseconds for basic loop executing " 
			    + numberOfIterations + " iterations." );
	System.out.println( "CallBenchmark: " 
			    + timeForCall + " milliseconds for " 
			    + numberOfIterations + " calls." );
    }
}
//stop extract CallBenchmark
